#tag Class
Protected Class WindowMenuItemBringAllToFront
Inherits WindowMenuItem
	#tag Event
		Function ActionSelectorName() As String
		  return "arrangeInFront:"
		End Function
	#tag EndEvent

	#tag Event
		Function CommandID() As OSType
		  const kHICommandBringAllToFront = "bfrt"
		  return kHICommandBringAllToFront
		End Function
	#tag EndEvent


	#tag Method, Flags = &h1
		Protected Function ShouldEnable() As Boolean
		  #if targetCocoa
		    declare function windowsMenu lib CocoaLib selector "windowsMenu" (id as Ptr) as Ptr
		    declare function itemArray lib CocoaLib selector "itemArray" (id as Ptr) as Ptr
		    declare function target lib CocoaLib selector "target" (id as Ptr) as Ptr
		    declare function isKindOfClass lib CocoaLib selector "isKindOfClass:" (id as Ptr, class_id as Ptr) as Boolean
		    declare function NSClassFromString lib CocoaLib (aClassName as CFStringRef) as Ptr
		    
		    
		    dim winMenu as Ptr = windowsMenu(NSApp)
		    if winMenu = nil then
		      return false
		    end if
		    
		    dim windowsFound as Boolean = false
		    dim winMenuItems as new CFArray(itemArray(winMenu), not CFType.hasOwnership)
		    for i as Integer = 0 to winMenuItems.Count - 1
		      dim p as Ptr = winMenuItems.Value(i)
		      dim w as Ptr = target(p)
		      if isKindOfClass(w, NSClassFromString("NSWindow")) then
		        windowsFound = true
		        exit
		      end if
		    next
		    
		    return windowsFound
		  #endif
		  
		  
		End Function
	#tag EndMethod


	#tag Constant, Name = MenuItemText, Type = String, Dynamic = True, Default = \"Bring All To Front", Scope = Private
		#Tag Instance, Platform = Any, Language = en, Definition  = \"Bring All To Front"
		#Tag Instance, Platform = Any, Language = Default, Definition  = \"Alle nach vorne bringen"
		#Tag Instance, Platform = Any, Language = fr, Definition  = \"Tout ramener au premier plan"
		#Tag Instance, Platform = Any, Language = it, Definition  = \"Porta tutto in primo piano"
	#tag EndConstant


	#tag ViewBehavior
		#tag ViewProperty
			Name="AutoEnable"
			Group="Behavior"
			InitialValue="0"
			Type="Boolean"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Checked"
			Group="Behavior"
			InitialValue="0"
			Type="Boolean"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="CommandKey"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Enabled"
			Group="Behavior"
			InitialValue="0"
			Type="Boolean"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Icon"
			Group="Behavior"
			InitialValue="0"
			Type="Picture"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Index"
			Visible=true
			Group="ID"
			InitialValue="-2147483648"
			Type="Integer"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="KeyboardShortcut"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Left"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Name"
			Visible=true
			Group="ID"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Super"
			Visible=true
			Group="ID"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Text"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Top"
			Visible=true
			Group="Position"
			InitialValue="0"
			InheritedFrom="Object"
		#tag EndViewProperty
		#tag ViewProperty
			Name="Visible"
			Group="Behavior"
			InitialValue="0"
			Type="Boolean"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_mIndex"
			Group="Behavior"
			InitialValue="0"
			Type="Integer"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
		#tag ViewProperty
			Name="_mName"
			Group="Behavior"
			Type="String"
			EditorType="MultiLineEditor"
			InheritedFrom="MenuItem"
		#tag EndViewProperty
	#tag EndViewBehavior
End Class
#tag EndClass
